<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/mystyle.css" />
	</head>

	<body>
		<style>
			.mui-media {
				background: #fff;
			}
			
			.opclist-title {
				font-size: 16px;
			}
		</style>

		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">历史巡查信息</h1>
		</header>
		<div class="mui-content" id="list_content">
			<!--登陆记录列表，js动态插入-->
			<p id="patrolTotal" class="mui-margin-sm"></p>

			<div id="newPatrol" class="box-shadow" style="width: 60px;height:60px;bottom:40px;background-color:#005dff;color:#fff;z-index: 1;position:fixed;margin-left:75%;padding-left:15px;padding-top:15px;font-size:60px;text-align: left;line-height:30px;background-repeat:no-repeat;background-position-y: center;background-size:150px;border-radius: 40px;">+</div>
			<!--						<div class="box-shadow" style="width: 120px;height:30px;bottom:40px;background-color:#005dff;color:#fff;z-index: 1;position:absolute;margin-left:60%;padding-left:15px;font-size:14px;text-align: left;line-height:30px;background-repeat:no-repeat;background-position-y: center;background-size:150px;border-radius: 20px;">+ 新增巡查信息</div>
-->
		</div>

		<script src="../lib/mui/mui.min.js"></script>
		<script src="../lib/jquery-2.1.0.min.js" type="text/javascript"></script>
		<script src="../js/serviceUrlConfig.js" type="text/javascript"></script>
		<script src="../js/winVisibleControl.js" type="text/javascript"></script>
		<script type="text/javascript">
			(function($, doc) {
				mui.init({
					//					pullRefresh: {
					//						 container:".mui-content",
					//						down: {
					//							callback: pulldownRefresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					//						}
					//					}
				})

				var feature, userInfo, locationInfo,lastPatrolValue;
				
				window.addEventListener('refresh', function() {
					location.reload(); //父页面仅仅是刷新页面，当然也可以自定义逻辑函数写在里面 
				})
				$.plusReady(function() {
					//获取用户编号
					var selfInfo = plus.webview.currentWebview();
					plus.navigator.setStatusBarStyle('dark');
					feature = selfInfo.param.feature;
					userInfo = selfInfo.param.userInfo;
					locationInfo = selfInfo.param.locationInfo;
					var log = [];
					var url = getServletUrl("PatrolServlet");
					pulldownRefresh();

					function pulldownRefresh() {
						$.ajax({
							type: "POST",
							url: url,
							data: {
								commdCode: "getPatrolList",
								userid: userInfo.id,
								sbbh: (feature.properties.水表编号 || feature.properties.sbbh)
							},
							dataType: "json",
							success: function(data) {
								if(data.type = 1) {
									log = data.tag;
									if(log.length < 1) {
										$('#patrolTotal')[0].innerText = '无历史巡查信息';
										//设置默认值
										lastPatrolValue={backNowValue:0,backTotalValue:0,electricType:'电池',equipmentType:'流量计'}
										
									} else {
										$('#patrolTotal')[0].innerText = log.length + '条历史巡查信息';
										lastPatrolValue={backNowValue:log[0].backNowValue?log[0].backNowValue:0,
											backTotalValue:log[0].backTotalValue?log[0].backTotalValue:0,
											electricType:log[0].electricType?log[0].electricType:'电池',
											equipmentType:log[0].equipmentType?log[0].equipmentType:'流量计'}
									}
								} else {
									log = [];
								}
								displayHistory(log);
							},
							error: function(xhr, type, errorThrown) {
								mui.alert("服务器连接失败，请联系管理员！", "提示");
							}
						});
					}

					document.getElementById("newPatrol").addEventListener("tap", function() {
						//					$('#newPatrol').on('tap', function() {
						var id = "../html/picture.html";
						var href = "../html/picture.html";
						var title = "巡查上报";
						// 带上用户信息
						openNewWindow(id, href, title, {
							feature: feature,
							userInfo: userInfo,
							locationInfo: locationInfo,
							lastPatrolValue:lastPatrolValue
						});
					})

					function displayHistory(log) {
						var content = document.getElementById("list_content");
						var ul = document.createElement("ul");
						ul.classList.add("mui-table-view");
						content.appendChild(ul);
//						log=log.length>0?log.reverse():[];
						for(var i = 0; i < log.length; i++) {
							var li = document.createElement("li");
							li.classList.add("mui-table-view-cell", "mui-media");
							var a = document.createElement("a");
							a.id = log[i].id; //a标签的id设置为日志行的主键id
							a.classList.add("opclist-title");
							var img = document.createElement("img");
							img.classList.add("mui-media-object", "mui-pull-left");
							var div = document.createElement("div");
							div.classList.add("mui-media-body");
							var p = document.createElement("p");
							p.classList.add("mui-ellipsis");
							var p1 = document.createElement("p");
							p1.classList.add("mui-ellipsis");
							var span = document.createElement("span");
							img.src = "../img/clock.svg";
							span.innerText = log[i].submitTime + " ";
							p.innerText = '水表编号: ' +
								log[i].sbbh;
							p1.innerText = '上报内容: ' +
								log[i].content;
							li.appendChild(a);
							a.appendChild(img);
							a.appendChild(div);
							div.appendChild(span);
							div.appendChild(p);
							div.appendChild(p1);
							ul.appendChild(li);
						}

					}

				});
			}(mui, document));
		</script>
	</body>

</html>